home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / bench.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  12.7 KB  |  444 lines

  1. /* pop (%!) .skipeof
  2.  
  3.    Copyright (C) 1989, 1995, 2000 Aladdin Enterprises.  All rights reserved.
  4.   
  5.   This file is part of AFPL Ghostscript.
  6.   
  7.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  8.   distributor accepts any responsibility for the consequences of using it, or
  9.   for whether it serves any particular purpose or works at all, unless he or
  10.   she says so in writing.  Refer to the Aladdin Free Public License (the
  11.   "License") for full details.
  12.   
  13.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  14.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  15.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  16.   conditions described in the License.  Among other things, the License
  17.   requires that the copyright notice and this notice be preserved on all
  18.   copies.
  19. */
  20.  
  21. /*$Id: bench.c,v 1.3.2.1 2000/11/10 00:04:02 rayjj Exp $ */
  22. /* Simple hardware benchmarking suite (C and PostScript) */
  23. #include "stdio_.h"
  24. #include <stdlib.h>
  25.  
  26. /* Patchup for GS externals */
  27. FILE *gs_stdout;
  28. FILE *gs_stderr;
  29. FILE *gs_debug_out;
  30. const char gp_scratch_file_name_prefix[] = "gs_";
  31. static void
  32. capture_stdio(void)
  33. {
  34.     gs_stdout = stdout;
  35.     gs_stderr = stderr;
  36.     gs_debug_out = stderr;
  37. }
  38. #include "gsio.h"
  39. #undef gs_stdout
  40. #undef gs_stderr
  41. #undef stdout
  42. #define stdout gs_stdout
  43. #undef stderr
  44. #define stderr gs_stderr
  45. FILE *
  46. gp_open_scratch_file(const char *prefix, char *fname, const char *mode)
  47. {
  48.     return NULL;
  49. }
  50. void 
  51. gp_set_printer_binary(int prnfno, int binary)
  52. {
  53. }
  54. void 
  55. gs_exit(int n)
  56. {
  57.     exit(n);
  58. }
  59. #define eprintf_program_ident(f, pn, rn) (void)0
  60. void 
  61. lprintf_file_and_line(FILE * f, const char *file, int line)
  62. {
  63.     fprintf(f, "%s(%d): ", file, line);
  64. }
  65.  
  66. /*
  67.  * Read the CPU time (in seconds since an implementation-defined epoch)
  68.  * into ptm[0], and fraction (in nanoseconds) into ptm[1].
  69.  */
  70. #include "gp_unix.c"
  71. #undef stdout
  72. #define stdout gs_stdout
  73. #undef stderr
  74. #define stderr gs_stderr
  75.  
  76. /* Loop unrolling macros */
  77. #define do10(x) x;x;x;x;x; x;x;x;x;x
  78.  
  79. /* Define the actual benchmarks. */
  80. static int
  81. iadd(int a, int n, char **msg)
  82. {
  83.     int b = 0, i;
  84.  
  85.     for (i = n / 20; --i >= 0;) {
  86.     do10((b += a, b += i));
  87.     }
  88.     *msg = "integer adds";
  89.     return b;
  90. }
  91. static int
  92. imul(int a, int n, char **msg)
  93. {
  94.     int b = 1, i;
  95.  
  96.     for (i = n / 20; --i > 0;) {
  97.     do10((b *= a, b *= i));
  98.     }
  99.     *msg = "integer multiplies";
  100.     return b;
  101. }
  102. static int
  103. idiv(int a, int n, char **msg)
  104. {
  105.     int b = 1, i;
  106.  
  107.     for (i = n / 20; --i > 0;) {
  108.     b += 999999;
  109.     do10((b /= a, b /= i));
  110.     }
  111.     *msg = "integer divides";
  112.     return b;
  113. }
  114. static int
  115. fadd(float a, int n, char **msg)
  116. {
  117.     float b = 0;
  118.     int i;
  119.  
  120.     for (i = n / 10; --i >= 0;) {
  121.     do10((b += a));
  122.     }
  123.     *msg = "floating adds";
  124.     return b;
  125. }
  126. static int
  127. fmul(float a, int n, char **msg)
  128. {
  129.     float b = 1;
  130.     int i;
  131.  
  132.     for (i = n / 10; --i >= 0;) {
  133.     do10((b *= a));
  134.     }
  135.     *msg = "floating multiplies";
  136.     return b;
  137. }
  138. static int
  139. fdiv(float a, int n, char **msg)
  140. {
  141.     float b = 1;
  142.     int i;
  143.  
  144.     for (i = n / 10; --i >= 0;) {
  145.     do10((b /= a));
  146.     }
  147.     *msg = "floating divides";
  148.     return b;
  149. }
  150. static int
  151. fconv(int a, int n, char **msg)
  152. {
  153.     int b[10];
  154.     float f[10];
  155.     int i;
  156.  
  157.     b[0] = a;
  158.     for (i = n / 20; --i >= 0;)
  159.     f[0] = b[0], f[1] = b[1], f[2] = b[2], f[3] = b[3], f[4] = b[4],
  160.         f[5] = b[5], f[6] = b[6], f[7] = b[7], f[8] = b[8], f[9] = b[9],
  161.         b[0] = f[1], b[1] = f[2], b[2] = f[3], b[3] = f[4], b[4] = f[5],
  162.         b[5] = f[6], b[6] = f[7], b[7] = f[8], b[8] = f[9], b[9] = f[0];
  163.     *msg = "float/int conversions";
  164.     return b[0];
  165. }
  166. static int
  167. mfast(int *m, int n, char **msg)
  168. {
  169.     int i;
  170.  
  171.     m[0] = n;
  172.     for (i = n / 20; --i >= 0;)
  173.     m[9] = m[8], m[8] = m[7], m[7] = m[6], m[6] = m[5], m[5] = m[4],
  174.         m[4] = m[3], m[3] = m[2], m[2] = m[1], m[1] = m[0], m[0] = m[9];
  175.     *msg = "fast memory accesses";
  176.     return m[0];
  177. }
  178. static int
  179. mslow(int *m, int n, char **msg)
  180. {
  181.     int *p;
  182.     int i, k = 0;
  183.  
  184.     m[0] = n;
  185.     for (i = n / 20; --i >= 0; k = (k + 397) & 0x3ffff)
  186.     p = m + k,
  187.         p[0] = p[100], p[20] = p[120], p[40] = p[140],
  188.         p[60] = p[160], p[80] = p[180],
  189.         p[200] = p[300], p[220] = p[320], p[240] = p[340],
  190.         p[260] = p[360], p[280] = p[380];
  191.     *msg = "slow memory accesses";
  192.     return m[0];
  193. }
  194.  
  195. int
  196. main(int argc, const char *argv[])
  197. {
  198.     int i;
  199.     int *mem = malloc(1100000);
  200.  
  201.     capture_stdio();
  202.     for (i = 0;; ++i) {
  203.     long t0[2], t1[2];
  204.     char *msg;
  205.     int n;
  206.  
  207.     gp_get_usertime(t0);
  208.     switch (i) {
  209.         case 0:
  210.         iadd(0, n = 10000000, &msg);
  211.         break;
  212.         case 1:
  213.         imul(1, n = 1000000, &msg);
  214.         break;
  215.         case 2:
  216.         idiv(1, n = 1000000, &msg);
  217.         break;
  218.         case 3:
  219.         fadd(3.14, n = 10000000, &msg);
  220.         break;
  221.         case 4:
  222.         fmul(1.0000001, n = 10000000, &msg);
  223.         break;
  224.         case 5:
  225.         fdiv(1.0000001, n = 1000000, &msg);
  226.         break;
  227.         case 6:
  228.         fconv(12345, n = 10000000, &msg);
  229.         break;
  230.         case 7:
  231.         mfast(mem, n = 10000000, &msg);
  232.         break;
  233.         case 8:
  234.         mslow(mem, n = 1000000, &msg);
  235.         break;
  236.         default:
  237.         free(mem);
  238.         exit(0);
  239.     }
  240.     gp_get_usertime(t1);
  241.     fprintf(stdout, "Time for %9d %s = %g ms\n", n, msg,
  242.         (t1[0] - t0[0]) * 1000.0 + (t1[1] - t0[1]) / 1000000.0);
  243.     fflush(stdout);
  244.     }
  245. }
  246.  
  247. /*
  248.    Output from SPARCstation 10, gcc -O bench.c gp_unix.c:
  249.  
  250.    Time for  10000000 integer adds = 113.502 ms
  251.    Time for   1000000 integer multiplies = 467.965 ms
  252.    Time for   1000000 integer divides = 594.328 ms
  253.    Time for  10000000 floating adds = 641.21 ms
  254.    Time for  10000000 floating multiplies = 643.357 ms
  255.    Time for   1000000 floating divides = 131.995 ms
  256.    Time for  10000000 float/int conversions = 602.061 ms
  257.    Time for  10000000 fast memory accesses = 201.048 ms
  258.    Time for   1000000 slow memory accesses = 552.606 ms
  259.  
  260.    Output from 486DX/25, wcl386 -oit bench.c gp_iwatc.c gp_msdos.c:
  261.  
  262.    Time for  10000000 integer adds = 490 ms
  263.    Time for   1000000 integer multiplies = 770 ms
  264.    Time for   1000000 integer divides = 1860 ms
  265.    Time for  10000000 floating adds = 4070 ms
  266.    Time for  10000000 floating multiplies = 4450 ms
  267.    Time for   1000000 floating divides = 2470 ms
  268.    Time for  10000000 float/int conversions = 25650 ms
  269.    Time for  10000000 fast memory accesses = 990 ms
  270.    Time for   1000000 slow memory accesses = 330 ms
  271.  
  272.  */
  273.  
  274. /*
  275.    The rest of this file contains a similar benchmark in PostScript.
  276.  
  277.    %!
  278.    /timer               % <str> <N> <proc> timer
  279.    { bind 2 copy usertime mark 4 2 roll repeat cleartomark usertime exch sub
  280.    % Stack: str N proc dt
  281.    exch pop
  282.    (Time for ) print exch =only ( ) print exch =only (: ) print
  283.    =only ( ms
  284.    ) print flush
  285.    } def
  286.  
  287.    (x 20 integer adds) 5000 { 0
  288.    0 add 0 add 0 add 0 add 0 add 0 add 0 add 0 add 0 add 0 add
  289.    0 add 0 add 0 add 0 add 0 add 0 add 0 add 0 add 0 add 0 add
  290.    pop } timer
  291.  
  292.    (x 20 integer multiplies) 5000 { 1
  293.    3 mul 3 mul 3 mul 3 mul 3 mul 3 mul 3 mul 3 mul 3 mul 3 mul
  294.    3 mul 3 mul 3 mul 3 mul 3 mul 3 mul 3 mul 3 mul 3 mul 3 mul
  295.    pop } timer
  296.  
  297.    (x 20 integer divides) 5000 { 1000000000
  298.    3 idiv 3 idiv 3 idiv 3 idiv 3 idiv 3 idiv 3 idiv 3 idiv 3 idiv 3 idiv
  299.    3 idiv 3 idiv 3 idiv 3 idiv 3 idiv 3 idiv 3 idiv 3 idiv 3 idiv 3 idiv
  300.    pop } timer
  301.  
  302.    (x 20 floating adds) 5000 { 0.0
  303.    1.0 add 1.0 add 1.0 add 1.0 add 1.0 add 1.0 add 1.0 add 1.0 add 1.0 add 1.0 add
  304.    1.0 add 1.0 add 1.0 add 1.0 add 1.0 add 1.0 add 1.0 add 1.0 add 1.0 add 1.0 add
  305.    pop } timer
  306.  
  307.    (x 20 floating multiplies) 5000 { 1.0
  308.    2.3 mul 2.3 mul 2.3 mul 2.3 mul 2.3 mul 2.3 mul 2.3 mul 2.3 mul 2.3 mul 2.3 mul
  309.    2.3 mul 2.3 mul 2.3 mul 2.3 mul 2.3 mul 2.3 mul 2.3 mul 2.3 mul 2.3 mul 2.3 mul
  310.    pop } timer
  311.  
  312.    (x 20 floating divides) 5000 { 1.0
  313.    2.3 div 2.3 div 2.3 div 2.3 div 2.3 div 2.3 div 2.3 div 2.3 div 2.3 div 2.3 div
  314.    2.3 div 2.3 div 2.3 div 2.3 div 2.3 div 2.3 div 2.3 div 2.3 div 2.3 div 2.3 div
  315.    pop } timer
  316.  
  317.    (x 20 float/int conversions) 5000 { 12345.0
  318.    cvi cvr cvi cvr cvi cvr cvi cvr cvi cvr
  319.    cvi cvr cvi cvr cvi cvr cvi cvr cvi cvr
  320.    pop } timer
  321.  
  322.    /S 2048 string def
  323.    (x 10000(byte) fast memory accesses) 1000 {
  324.    //S 1024 1000 getinterval //S copy pop
  325.    //S 1024 1000 getinterval //S copy pop
  326.    //S 1024 1000 getinterval //S copy pop
  327.    //S 1024 1000 getinterval //S copy pop
  328.    //S 1024 1000 getinterval //S copy pop
  329.    } timer
  330.  
  331.    /A [ 500 { 2048 string } repeat ] def
  332.    (x 500 x 2000(byte) slower memory accesses) 10 {
  333.    0 1 499 {
  334.    //A exch get dup 1024 1000 getinterval exch copy pop
  335.    } for
  336.    } timer
  337.  
  338.    /Times-Roman findfont 36 scalefont setfont
  339.    currentcacheparams pop pop 0 1 index setcacheparams
  340.    /D [4 0 0 4 0 0] 1440 1440 <00 ff> makeimagedevice def
  341.    D setdevice
  342.    72 72 translate
  343.    gsave 15 rotate
  344.    0 0 moveto (A) show
  345.    (x 10 (A) show (cache)) 100 {
  346.    0 0 moveto
  347.    (A) show (A) show (A) show (A) show (A) show
  348.    (A) show (A) show (A) show (A) show (A) show
  349.    } timer grestore
  350.  
  351.    0 setcachelimit
  352.    gsave 10 rotate
  353.    (x 10 (A) show (no cache)) 10 {
  354.    0 0 moveto
  355.    (A) show (A) show (A) show (A) show (A) show
  356.    (A) show (A) show (A) show (A) show (A) show
  357.    } timer grestore
  358.  
  359.    quit
  360.  
  361.    Results for SUN Sparc 2 (rated at 25 MIPS according to manual)
  362.  
  363.    ./gs
  364.    Now in gs_init.ps
  365.    TextAlphaBits defined GraphicsAlphaBits defined
  366.    Aladdin Ghostscript 3.50 (1995-9-24)
  367.    (c) 1995 Aladdin Enterprises, Menlo Park, CA.  All rights reserved. This 
  368.    software comes with NO WARRANTY: see the file PUBLIC for details. Leaving 
  369.    gs_init.ps
  370.    GS>(ben1.c) run
  371.    Time for 5000 x 20 integer adds: 171 ms
  372.    Time for 5000 x 20 integer multiplies: 504 ms
  373.    Time for 5000 x 20 integer divides: 334 ms
  374.    Time for 5000 x 20 floating adds: 148 ms 
  375.    Time for 5000 x 20 floating multiplies: 165 ms
  376.    Time for 5000 x 20 floating divides: 194 ms 
  377.    Time for 5000 x 20 float/int conversions: 121 ms
  378.    Time for 1000 x 10000(byte) fast memory accesses: 112 ms
  379.    Time for 10 x 500 x 2000(byte) slower memory accesses: 236 ms
  380.    Loading NimbusRomanNo9L-Regular font from 
  381.    [...]/n021003l.gsf... 1739080 414724 2564864 1251073 0 
  382.    done. Time for 100 x 10 (A) show (cache): 144 ms
  383.    Time for 10 x 10 (A) show (no cache): 538 ms
  384.  
  385.    Output from SPARCstation 10, gs 3.60 compiled with gcc -g -O -DDEBUG:
  386.  
  387.    gsnd bench.c
  388.    Aladdin Ghostscript 3.60 (1995-10-23)
  389.    Copyright (C) 1995 Aladdin Enterprises, Menlo Park, CA.  All rights reserved.
  390.    This software comes with NO WARRANTY: see the file PUBLIC for details.
  391.    Time for 5000 x 20 integer adds: 192 ms
  392.    Time for 5000 x 20 integer multiplies: 561 ms
  393.    Time for 5000 x 20 integer divides: 396 ms
  394.    Time for 5000 x 20 floating adds: 202 ms
  395.    Time for 5000 x 20 floating multiplies: 247 ms
  396.    Time for 5000 x 20 floating divides: 243 ms
  397.    Time for 5000 x 20 float/int conversions: 157 ms
  398.    Time for 1000 x 10000(byte) fast memory accesses: 136 ms
  399.    Time for 10 x 500 x 2000(byte) slower memory accesses: 235 ms
  400.    Loading Temps-RomanSH font from /opt/home/peter/gs/fonts/soho/tersh___.pfb... 1759156 432729 2564864 1251025 0 done.
  401.    Time for 100 x 10 (A) show (cache): 161 ms
  402.    Time for 10 x 10 (A) show (no cache): 449 ms
  403.  
  404.    Output from 486DX/25, gs 2.6.1 compiled with wcc386 -oi[t]:
  405.  
  406.    gsndt bench.c
  407.    Initializing... done.
  408.    Ghostscript 2.6.1 (5/28/93)
  409.    Copyright (C) 1990-1993 Aladdin Enterprises, Menlo Park, CA.
  410.    All rights reserved.
  411.    Ghostscript comes with NO WARRANTY: see the file COPYING for details.
  412.    Time for 5000 x 20 integer adds: 550 ms
  413.    Time for 5000 x 20 integer multiplies: 940 ms
  414.    Time for 5000 x 20 integer divides: 880 ms
  415.    Time for 5000 x 20 floating adds: 550 ms
  416.    Time for 5000 x 20 floating multiplies: 660 ms
  417.    Time for 5000 x 20 floating divides: 930 ms
  418.    Time for 5000 x 20 float/int conversions: 830 ms
  419.    Time for 1000 x 10000(byte) fast memory accesses: 660 ms
  420.    Time for 10 x 500 x 2000(byte) slower memory accesses: 540 ms
  421.    Loading Temps-RomanSH font from c:\gs\fonts\softhorz\tersh___.pfb... 1298792 1207949 0 done.
  422.    Time for 100 x 10 (A) show (cache): 13520 ms
  423.    Time for 10 x 10 (A) show (no cache): 1310 ms
  424.  
  425.    Output from 486DX/25, gs 3.52 compiled with wcc386 -oi[t]:
  426.  
  427.    Aladdin Ghostscript 3.52 (1995-10-2)
  428.    Copyright (c) 1995 Aladdin Enterprises, Menlo Park, CA.  All rights reserved.
  429.    This software comes with NO WARRANTY: see the file PUBLIC for details.
  430.    Time for 5000 x 20 integer adds: 660 ms
  431.    Time for 5000 x 20 integer multiplies: 1100 ms
  432.    Time for 5000 x 20 integer divides: 940 ms
  433.    Time for 5000 x 20 floating adds: 710 ms
  434.    Time for 5000 x 20 floating multiplies: 830 ms
  435.    Time for 5000 x 20 floating divides: 1040 ms
  436.    Time for 5000 x 20 float/int conversions: 820 ms
  437.    Time for 1000 x 10000(byte) fast memory accesses: 660 ms
  438.    Time for 10 x 500 x 1000(byte) slower memory accesses: 600 ms
  439.    Loading Temps-RomanSH font from c:\gs\fonts\softhorz\tersh___.pfb... 1678548 375231 2564864 1250964 0 done.
  440.    Time for 100 x 10 (A) show (cache): 2520 ms
  441.    Time for 10 x 10 (A) show (no cache): 1600 ms
  442.  
  443.  */
  444.